/*******************************************************************************
 * Copyright (c) 2009 Brian Edginton and Aaron Getz.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Brian Edginton - initial API and implementation
 *     Aaron Getz
 *******************************************************************************/

package org.eclipse.mylyn.internal.eplanner.ui.editor;

import org.eclipse.mylyn.internal.eplanner.core.EPlannerCorePlugin;
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
import org.eclipse.mylyn.tasks.ui.ITasksUiConstants;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPageFactory;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.forms.editor.IFormPage;

public class EPlannerTaskEditorPageFactory extends AbstractTaskEditorPageFactory {
	
	private static final String PAGE_TEXT = "EPlanner";

	@Override
	public boolean canCreatePageFor(TaskEditorInput input) {
		if ((input.getTask().getConnectorKind().equals(EPlannerCorePlugin.CONNECTOR_KIND))
				|| TasksUiUtil.isOutgoingNewTask(input.getTask(), EPlannerCorePlugin.CONNECTOR_KIND)) {
			return true;
		}
		return false;
	}

	@Override
	public IFormPage createPage(TaskEditor parentEditor) {
		return new EPlannerTaskEditorPage(parentEditor);
	}
	
	@Override
	public String[] getConflictingIds(TaskEditorInput input) {
		if (!input.getTask().getConnectorKind().equals(EPlannerCorePlugin.CONNECTOR_KIND)) {
			return new String[] {ITasksUiConstants.ID_PAGE_PLANNING};
		}
		return null;
	}

	@Override
	// TODO Remove suppression of restriction once eplanner is incubated.
	@SuppressWarnings("restriction")  
	public Image getPageImage() {
		return CommonImages.getImage(TasksUiImages.REPOSITORY_SMALL);
	}

	@Override
	public String getPageText() {
		return PAGE_TEXT;
	}
	
	@Override
	public int getPriority() {
		return PRIORITY_TASK;
	}
}
